package com.gonsin.ta.logic.config;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
@Getter
public class BaseTaConfig {

    /**
     * 默认ta脚本存放的目录
     */
    @Value("${com.gonsin.ta.defaultTaPath:ta}")
    private String defaultTaPath;

    @Value("${com.gonsin.ta.charset:utf8}")
    private String fileCharset;

    @Value("${com.gonsin.ta.cli.user:admin}")
    private String user;

    @Value("${com.gonsin.ta.cli.password:11111111}")
    private String password;

    @Value("${com.gonsin.ta.cli.whiteList:}")
    private List<String> whiteList;

    @Value("${com.gonsin.ta.cli.blackList:}")
    private List<String> blackList;



    private volatile boolean first = true;

    public String getDefaultTaPath() {
        if(first){
            synchronized (BaseTaConfig.class){
                if(first){
                    if(!defaultTaPath.endsWith("/")){
                        defaultTaPath += "/";
                    }
                    if(defaultTaPath.startsWith("/")){
                        defaultTaPath = defaultTaPath.substring(1);
                    }
                }
                first = false;
            }
        }
        return defaultTaPath;
    }
}
